package com.crm.miaohe.mapper;

import com.crm.miaohe.model.TblUserOpenid;
import com.crm.miaohe.model.TblUserOpenidExample;
import java.util.List;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.ResultMap;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectKey;
import org.apache.ibatis.annotations.Update;

@Mapper
public interface TblUserOpenidMapper {
    long countByExample(TblUserOpenidExample example);

    int deleteByExample(TblUserOpenidExample example);

    @Delete({
        "delete from tbl_user_openid",
        "where id = #{id,jdbcType=BIGINT}"
    })
    int deleteByPrimaryKey(Long id);

    @Insert({
        "insert into tbl_user_openid (user_id, phone_number, ",
        "user_name, open_id, ",
        "access_token, expires_in, ",
        "refresh_token, scope, ",
        "create_time, create_user, ",
        "update_time, update_user, ",
        "version)",
        "values (#{userId,jdbcType=BIGINT}, #{phoneNumber,jdbcType=VARCHAR}, ",
        "#{userName,jdbcType=VARCHAR}, #{openId,jdbcType=VARCHAR}, ",
        "#{accessToken,jdbcType=VARCHAR}, #{expiresIn,jdbcType=VARCHAR}, ",
        "#{refreshToken,jdbcType=VARCHAR}, #{scope,jdbcType=VARCHAR}, ",
        "#{createTime,jdbcType=TIMESTAMP}, #{createUser,jdbcType=VARCHAR}, ",
        "#{updateTime,jdbcType=TIMESTAMP}, #{updateUser,jdbcType=VARCHAR}, ",
        "#{version,jdbcType=BIGINT})"
    })
    @SelectKey(statement="SELECT LAST_INSERT_ID()", keyProperty="id", before=false, resultType=Long.class)
    int insert(TblUserOpenid record);

    int insertSelective(TblUserOpenid record);

    List<TblUserOpenid> selectByExample(TblUserOpenidExample example);

    @Select({
        "select",
        "id, user_id, phone_number, user_name, open_id, access_token, expires_in, refresh_token, ",
        "scope, create_time, create_user, update_time, update_user, version",
        "from tbl_user_openid",
        "where id = #{id,jdbcType=BIGINT}"
    })
    @ResultMap("com.crm.miaohe.mapper.TblUserOpenidMapper.BaseResultMap")
    TblUserOpenid selectByPrimaryKey(Long id);

    int updateByExampleSelective(@Param("record") TblUserOpenid record, @Param("example") TblUserOpenidExample example);

    int updateByExample(@Param("record") TblUserOpenid record, @Param("example") TblUserOpenidExample example);

    int updateByPrimaryKeySelective(TblUserOpenid record);

    @Update({
        "update tbl_user_openid",
        "set user_id = #{userId,jdbcType=BIGINT},",
          "phone_number = #{phoneNumber,jdbcType=VARCHAR},",
          "user_name = #{userName,jdbcType=VARCHAR},",
          "open_id = #{openId,jdbcType=VARCHAR},",
          "access_token = #{accessToken,jdbcType=VARCHAR},",
          "expires_in = #{expiresIn,jdbcType=VARCHAR},",
          "refresh_token = #{refreshToken,jdbcType=VARCHAR},",
          "scope = #{scope,jdbcType=VARCHAR},",
          "create_time = #{createTime,jdbcType=TIMESTAMP},",
          "create_user = #{createUser,jdbcType=VARCHAR},",
          "update_time = #{updateTime,jdbcType=TIMESTAMP},",
          "update_user = #{updateUser,jdbcType=VARCHAR},",
          "version = #{version,jdbcType=BIGINT}",
        "where id = #{id,jdbcType=BIGINT}"
    })
    int updateByPrimaryKey(TblUserOpenid record);
}